<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
<html class="no-js">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <title>软件管理平台</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width">
    <link href="../statics/css/common/common.css" rel='stylesheet'/>
    <link href="../statics/assets/bootstrap/css/bootstrap.min.css" rel='stylesheet'/>
    <%--<script src="../statics/assets/jquery/jquery-3.1.0.js"></script>--%>
    <script src="../statics/assets/jquery/jquery-3.1.0.min.js"></script>
    <script src="../statics/assets/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" language="javascript">
        var basePath = "<%=basePath%>";
        var softwareId = getUrlParam('softwareId');
      	function getUrlParam(name) {
      		 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
      		 var r = window.location.search.substr(1).match(reg); //匹配目标参数
      		 if (r != null) return unescape(r[2]); return null; //返回参数值
      		}
      	
	
	function flowApprove() {
	        
			var softwareStr = {
					id:softwareId,
					name: $("#softName").val().trim(),
					categoryId: $('#btnCodeStr').val().trim(),
					icon: $("#srcUrl").val().trim(),
					description: $("#des").html().trim(),
		        };

	       $.ajax( {
	           url:basePath+"/SoftwareFlow/flowPass",
	           data:{
	        	   software:JSON.stringify(softwareStr)
	           },
	           dataType:'json',
	           success:function(data) {
	               if (data.status == "success") {
	            	   var r=confirm("审批通过,你要关闭当前窗口吗？");
	            	   if (r==true)
	            	   {
	            		   var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	                       parent.layer.close(index);
	            	   }else{
	            		   $("#approve").hide();
	            		   $("#repulse").hide();
	            	   }
	            	
	               } else {
	                   alert("请求失败！")
	               }
	           },
	           error : function() {
	               alert("异常！");
	           }
	       });

	};
	
	
	 function  flowRepulse(){
		       $.ajax( {
		           url:basePath+"/SoftwareFlow/flowRefuse",
		           data:{
		        	   softId:softwareId
		           },
		           dataType:'json',
		           success:function(data) {
		               if (data.status == "success") {
		            	   var r=confirm("驳回成功请,你要关闭当前窗口吗？");
		            	   if (r==true)
		            	   {
		            		   var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		                       parent.layer.close(index);
		            	   }else{
		            		                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
		            		   $("#approve").hide();
		            		   $("#repulse").hide();
		            		   
		            	   }
		               } else {
		                   alert("请求失败！")
		               }
		           },
		           error : function() {
		               alert("异常！");
		           }
		       });
		   };
		   
      	
      	
      	
      	
        $(document).ready(function(){
		       $.ajax( {
		           url:basePath+"/SoftwareFlow/getSoftwareById",
		           data:{
		        	   softId:softwareId
		           },
		           dataType:'json',
		           success:function(data) {
		        	   
		               if (data.status == "success") {
		            	   $("#softName").val(data.result.name);
		            	   $("#createTime").val(data.result.modifyTime);
		            	   $("#des").html(data.result.description);
		            	   $("#srcUrl").attr('src',basePath+data.result.icon); 
		            	   $("#downs").attr('href',basePath+data.result.downloadUrl); 
		            	   
			               	for (var i = 0; i < data.category.length; i++) {
			               		if(data.category[i].id==data.result.categoryId){
			               			
			               			
					               $('#btnCodeStr').append("<option value=" + data.category[i].id + " selected=true>" + data.category[i].name + "</option>");
	
			               		}else{
			               			
				                  $('#btnCodeStr').append("<option value=" + data.category[i].id + ">" + data.category[i].name + "</option>");
	
			               			
			               		}
			                }
		               } else {
		                   alert("请求失败！")
		               }
		           },
		           error : function() {
		               alert("异常！");
		           }
		       });
		       
		
	    });




    </script>

</head>
<body>
<div class="main">

<div class="form-horizontal" role="form"> 
    <div class="form-group"> 
    	<div class="col-md-2 text-left" style="font-weight: bold">LOGO:</div>
        <div class="col-sm-10"> 
       		<img id="srcUrl" class="app-img" style="width: 100px"  />
           <!--  <input type="image" class="form-control"  id="srcUrl">  -->
        </div> 
    </div> 

    <div class="form-group"> 
    	<div class="col-md-2 text-left" style="font-weight: bold">软件名:</div>
        <div class="col-sm-10"> 
            <input type="text" name="haha" class="form-control" style="width: 200px" id="softName"  > 
        </div> 
    </div> 
    <div class="form-group"> 
   		<div class="col-md-2 text-left" style="font-weight: bold">上传人:</div>
        <div class="col-sm-10"> 
            <input type="text" class="form-control" style="width: 200px" id="lastname"placeholder="张某某">
        </div> 
    </div> 
    <div class="form-group"> 
        <div class="col-md-2 text-left" style="font-weight: bold">上传时间:</div>
        <div class="col-sm-10"> 
            <input class="form-control" id="createTime" style="width: 200px" type="text" disabled> 
        </div> 
    </div>
    
     <div class="form-group"> 
        <div class="col-md-2 text-left" style="font-weight: bold">软件类型:</div>
     	<div class="col-sm-10" > 
	        <select id="btnCodeStr" name="sssss" class="form-control" style="width:200px"> 
	        </select> 
        </div>
    </div>
     <div class="form-group"> 
     	<div class="col-md-2 text-left" style="font-weight: bold">文件描述:</div>
     	<div class="col-sm-10"> 
        	<textarea id="des" class="form-control" rows="3" style="width: 500px"></textarea> 
        </div>
    </div> 
    <div class="form-group"> 
        <div class="col-sm-offset-2 col-sm-10"> 
            <button id="approve" type="button" class="btn btn-default" onclick="flowApprove()">通过</button> 
            <button id="repulse" type="button" class="btn btn-default" onclick="flowRepulse()">驳回</button> 
            <a  id="downs" class="btn btn-default" >下载</a>
        </div> 
    </div> 
</div>


</div>
</body>
</html>